class BookshopsController < ApplicationController
  before_filter :load_session
  after_filter :save_session

  private
  def load_session
    @currencies = Currency.find(:all, :order=>:name)
    @cities = City.find(:all, :order=>:name)
  end

  def save_session
  end

  public
  # GET /bookshops
  # GET /bookshops.xml
  def index
    @bookshops = Bookshop.all

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @bookshops }
    end
  end

  # GET /bookshops/1
  # GET /bookshops/1.xml
  def show
    @bookshop = Bookshop.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @bookshop }
    end
  end

  # GET /bookshops/new
  # GET /bookshops/new.xml
  def new
    @bookshop = Bookshop.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @bookshop }
    end
  end

  # GET /bookshops/1/edit
  def edit
    @bookshop = Bookshop.find(params[:id])
  end

  # POST /bookshops
  # POST /bookshops.xml
  def create
    @bookshop = Bookshop.new(params[:bookshop])

    respond_to do |format|
      if @bookshop.save
        flash[:notice] = 'Bookshop was successfully created.'
        format.html { redirect_to(@bookshop) }
        format.xml  { render :xml => @bookshop, :status => :created, :location => @bookshop }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @bookshop.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /bookshops/1
  # PUT /bookshops/1.xml
  def update
    @bookshop = Bookshop.find(params[:id])

    respond_to do |format|
      if @bookshop.update_attributes(params[:bookshop])
        flash[:notice] = 'Bookshop was successfully updated.'
        format.html { redirect_to(@bookshop) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @bookshop.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /bookshops/1
  # DELETE /bookshops/1.xml
  def destroy
    @bookshop = Bookshop.find(params[:id])
    @bookshop.destroy

    respond_to do |format|
      format.html { redirect_to(bookshops_url) }
      format.xml  { head :ok }
    end
  end
end
